import * as service from "@/service";
import IBrand from "./interface";
const brand: IBrand = {
  namespaced: true,
  state: {
    brandNav: [],
    brandOneData: [],
    brandTwoData: [],
    brandList: [],
  },
  actions: {
    async getBrandNav({ commit }) {
      const result = await service.fetchBrandNav();
      const action = {
        type: "GET_BRAND_NAV",
        payload: result?.data,
      };
      commit(action);
    },
    async getBrandOneData({ commit }) {
      const result = await service.fetchBrandData("one");
      const action = {
        type: "GET_BRAND_ONE_DATA",
        payload: result?.data?.brandDTOS,
      };
      commit(action);
    },
    async getBrandTwoData({ commit }) {
      const result = await service.fetchBrandData("two");
      const action = {
        type: "GET_BRAND_TWO_DATA",
        payload: result?.data?.brandDTOS,
      };
      commit(action);
    },

    async getBrandList({ commit }, { typeId }) {
      const result = await service.fetchBrandList(typeId);
      const action = {
        type: "GET_BRAND_LIST",
        payload: result?.data,
      };
      commit(action);
    },
  },
  mutations: {
    GET_BRAND_NAV(state, action) {
      action.payload.unshift({
        bottomImage: "",
        brandLimit: 0,
        id: 0,
        smallPic: "",
        sort: 0,
        title: "精选",
        topImage: "",
        typeId: 0,
      });
      state.brandNav = action.payload;
    },
    GET_BRAND_ONE_DATA(state, action) {
      state.brandOneData = action.payload;
    },
    GET_BRAND_TWO_DATA(state, action) {
      state.brandTwoData = action.payload;
    },
    GET_BRAND_LIST(state, action) {
      state.brandList = action.payload;
    },
  },
};

export default brand;
